{%extend name="Public:layout"/%}
    {%block name="title"%}
    <h2 class="mb20">
      权限管理 
    </h2>
    {%/block%}
    {%block name="contents"%}  
    <div class="heading clearfix">
      <div class="pull-left">
        <form class="form-inline" onsubmit="return false;" stverify="true" method="get" action="">
          <select class="st-dropdown" name="menuM_id" data-config="subId:'suboption'">
            <option value="0">所有</option>
           {%notempty name="menuMainList"%}
            {%foreach name="menuMainList" item="vo"%}            
            <option value="{%$vo.class_id%}" 
                 {%if condition="$menuM_id eq $vo['class_id']" %} selected {%/if%}>{%$vo.name%}</option>
            {%/foreach%}
           {%/notempty%}
          </select>
          <select class="st-dropdown" name="menuS_id" id="suboption" data-config="subId:'suboption1'">
            <option value="0">所有</option>
           {%notempty name="menuSubList"%}
            {%foreach name="menuSubList" item="vo"%}            
            <option value="{%$vo.class_id%}"
                 {%if condition="$menuS_id eq $vo['class_id']" %} selected {%/if%}>{%$vo.name%}</option>
            {%/foreach%}
           {%/notempty%}
          </select>
          <select class="st-dropdown" name="search_id" id="suboption1">
            <option value="0">所有</option>
           {%notempty name="searchList"%}
            {%foreach name="searchList" item="vo"%}            
            <option value="{%$vo.class_id%}"
                 {%if condition="$search_id eq $vo['class_id']" %} selected {%/if%}>{%$vo.name%}</option>
            {%/foreach%}
           {%/notempty%}
          </select>
          <input type="submit" class="btn" value="搜索">
        </form>
      </div>
      <div class="pull-right">
        <div class="notice" style="line-height: 20px; margin-right: 25px;">目前权限总数：{%:count($atomList)%}</div>
        <a title="添加权限" href="javascript:;" onclick="ST.todo('add','0')" class="btn mr5"><i class="icon i-add"></i> 添加权限</a>
      </div>
    </div>
    <table class="table table-listing table-hovered">
      <thead class="thead-gray">
      <tr>
        <th>编号</th>
        <th>名称</th>
        <th>权限结构</th>
        <th>动作名称</th>
        <th>动作内容</th>
        <th>是否显示</th>
        <th>管理</th>
      </tr>
      </thead>
      <tbody>     
    {%notempty name="atomList"%}
      {%foreach name="atomList" item="vo" key="keys"%}        
      <tr>
        <td>{%$vo.id%}</td>
        <td>
          {%$vo.name%}
        </td>
        <td>
          {%$vo.className%}
        </td>
        <td>
          {%$vo.func_name%}
        </td>
        <td>
          {%$vo.func_data%}
        </td>
        <td>{%if condition="($vo['hidden_type'] eq 1)"%}<span class="text-green">列表显示</span>{%else /%}<span class="text-red">列表隐藏</span>{%/if%}</td>
        <td>
          <a href="javascript:;" title="编辑权限" onclick="ST.todo('edit','{%$vo.id%}')"><i class="icon i-edit"></i></a>
          <a href="javascript:;" title="删除权限" onclick="ST.todo('del','{%$vo.id%}')"><i class="icon i-del"></i></a>
        </td>
      </tr>
    {%/foreach%}
   {%/notempty%}
      </tbody>
    </table>
    <div class="clearfix mt10">
      <div class="pull-right">
        <div class="pagination"></div>
      </div>
    </div>
   {%/block%}

{%block name="js"%}
<script>
  $.extend(ST.ACTION, {
    'del': "{%:U('/admin/admin/delatom')%}",//删除权限action地址
    'add': "{%:U('/admin/admin/saveatom')%}",//添加权限弹窗地址
    'edit': "{%:U('/admin/admin/saveatom')%}",//编辑权限弹窗地址
    'loadSub': "{%:U('/admin/admin/ajaxgetatomsub')%}"//读取子选项地址
  });
  $.extend(ST, {
    todoList: function () {

    },
    /**
     * 弹出添加窗口
     * @param id      数据id
     */
    add: function (id) {
      ST.editBox(ST.ACTION.add + '/id/' + id, {
        title: '添加权限',
        height: 500
      });
    },
    /**
     * 弹出编辑窗口
     * @param id      数据id
     */
    edit: function (id) {
      ST.editBox(ST.ACTION.edit + '/id/' + id, {
        title: '编辑权限',
        height: 500
      });
    },
    /**
     * 执行AJAX删除操作后刷新页面
     * @param id      数据id
     */
    del: function (id) {
      ST.execAJAX({
        url: ST.ACTION.del,     //服务端请求地址
        params: {id: id},       //发送到服务端的参数（如：{myparam:1}）
        massage: '确定删除吗？',       //提示信息（仅hasconfirm为true时有用）
        hasconfirm: true,       //提交前是否显示确认框
        succFun: function (j) {  //成功后的回调方法：刷新页面
          if (!j) return;
          if (j.data && j.data.url) {
            location.href = j.data.url;
          } else {
            ST.reload();
          }
        }
      });
      //更多选项参见common.js execAJAX方法
    },
    //批量删除
    delAll: function (ids) {
      var ids = ST.getSelectedValue().join(',');
      if(!ids){
        ST.tipMsg('请至少选择一项');
      }else{
        ST.del(ids);
      }
    },
    //获得选中值
    getSelectedValue: function () {
      var $options = $('.js-toggleall-target:checked'), arr = [];
      $options.each(function () {
        arr.push($(this).val());
      });
      return arr;
    }
  });
  ST.init();
</script>
{%/block%}